<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Changes the default external entity loader</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.libxml-get-last-error.html">libxml_get_last_error</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.libxml-set-streams-context.html">libxml_set_streams_context</a></div>
 <div class="up"><a href="ref.libxml.html">libxml 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.libxml-set-external-entity-loader" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">libxml_set_external_entity_loader</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0)</p><p class="refpurpose"><span class="refname">libxml_set_external_entity_loader</span> &mdash; <span class="dc-title">Changes the default external entity loader</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.libxml-set-external-entity-loader-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>libxml_set_external_entity_loader</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$resolver_function</code></span>
   )</div>

  <p class="para rdfs-comment">
   Changes the default external entity loader.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.libxml-set-external-entity-loader-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">resolver_function</code></em></dt>

    <dd>

     <p class="para">
      A <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> that takes three arguments. Two strings, a public id
      and system id, and a context (an array with four keys) as the third argument.
      This callback should return a resource, a string from which a resource can be
      opened, or <strong><code>NULL</code></strong>.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.libxml-set-external-entity-loader-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.libxml-set-external-entity-loader-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5321">
    <p><strong>Example #1 <span class="function"><strong>libxml_set_external_entity_loader()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$xml&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;XML<br /></span><span style="color: #DD0000">&lt;!DOCTYPE&nbsp;foo&nbsp;PUBLIC&nbsp;"-//FOO/BAR"&nbsp;"http://example.com/foobar"&gt;<br />&lt;foo&gt;bar&lt;/foo&gt;<br /></span><span style="color: #007700">XML;<br /><br /></span><span style="color: #0000BB">$dtd&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;DTD<br /></span><span style="color: #DD0000">&lt;!ELEMENT&nbsp;foo&nbsp;(#PCDATA)&gt;<br /></span><span style="color: #007700">DTD;<br /><br /></span><span style="color: #0000BB">libxml_set_external_entity_loader</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;(</span><span style="color: #0000BB">$public</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$system</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$context</span><span style="color: #007700">)&nbsp;use(</span><span style="color: #0000BB">$dtd</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$public</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$system</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$f&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"php://temp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r+"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$f</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dtd</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">rewind</span><span style="color: #007700">(</span><span style="color: #0000BB">$f</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$f</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />);<br /><br /></span><span style="color: #0000BB">$dd&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$r&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dd</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$dd</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">validate</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
string(10) &quot;-//FOO/BAR&quot;
string(25) &quot;http://example.com/foobar&quot;
array(4) {
    [&quot;directory&quot;]    =&gt; NULL
    [&quot;intSubName&quot;]   =&gt; NULL
    [&quot;extSubURI&quot;]    =&gt; NULL
    [&quot;extSubSystem&quot;] =&gt; NULL
}
bool(true)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.libxml-set-external-entity-loader-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.libxml-disable-entity-loader.html" class="function" rel="rdfs-seeAlso">libxml_disable_entity_loader()</a> - Disable the ability to load external entities</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.libxml-get-last-error.html">libxml_get_last_error</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.libxml-set-streams-context.html">libxml_set_streams_context</a></div>
 <div class="up"><a href="ref.libxml.html">libxml 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
